#include <iostream>
#include <cmath>

using namespace std;

const int N = 1e4 + 10; 

int arr[1010][5];
int sum[1010];
int n;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> arr[i][1] >> arr[i][2] >> arr[i][3];
		sum[i] = arr[i][1] + arr[i][2] + arr[i][3];
	}
	
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (abs(arr[i][1] - arr[j][1]) <= 5 && 
				abs(arr[i][2] - arr[j][2]) <= 5 &&
				abs(arr[i][3] - arr[j][3]) <= 5 &&
				abs(sum[i] - sum[j]) <= 10)
				cnt++;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}
